package org.westboy.mybatis.mapper;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.ResultType;
import org.apache.ibatis.annotations.Select;
import org.westboy.mybatis.model.MallbuilderProductOrder;
import tk.mybatis.mapper.common.Mapper;

import java.awt.*;
import java.util.List;

public interface MallbuilderProductOrderMapper extends Mapper<MallbuilderProductOrder> {

    @Select("select id,order_id,consignee,product_price,status,des,order_note, FROM_UNIXTIME(`create_time`,'%Y-%m-%d %H:%i:%s') as create_time" +
            " from mallbuilder_product_order " +
            " where parent_id=0 and buyer_id=0" +
            "    and  " +
            "    to_days(FROM_UNIXTIME(`create_time`,'%Y-%m-%d %H:%i:%s')) = to_days(now())  " +
            "    and " +
            "    status in (0,1,2,3,4,7)" +
            " order by create_time desc")
    @ResultMap("BaseResultMap")
    List<MallbuilderProductOrder> findTodayOrder();

    @Select("select count(0)  " +
            " from mallbuilder_product_order " +
            " where parent_id=0 and buyer_id=0" +
            "  and  " +
            "  to_days(FROM_UNIXTIME(`create_time`,'%Y-%m-%d %H:%i:%s')) = to_days(now()) " +
            "  and " +
            " status in (0,1,2,3,4,7)")
    @ResultType(Integer.class)
    Integer findTodayOrderCount();


    @Select("select   count(0) as count from mallbuilder_product_order where status =2 and  parent_id=0 and buyer_id=0 and  UNIX_TIMESTAMP(date_sub(now(),interval 10 SECOND))<=payment_time")
    @ResultType(Integer.class)
    Integer find10SecondOrderCount();

    @Select("select   count(0) as count from mallbuilder_product_order where status =7 and  parent_id=0 and buyer_id=0 and  UNIX_TIMESTAMP(date_sub(now(),interval 10 SECOND))<=create_time")
    @ResultType(Integer.class)
    Integer find10SecondOtherOrderCount();

    @Select("select   count(0) as count from mallbuilder_product_order where status =2 and  parent_id=0 and buyer_id=0 and paytype=2 and  UNIX_TIMESTAMP(date_sub(now(),interval 10 SECOND))<=create_time")
    @ResultType(Integer.class)
    Integer find10SecondOrderCountByPayType();

    @Select("select id from mallbuilder_product_order where order_id =#{orderId} and  parent_id=0 and buyer_id=0")
    @ResultType(Integer.class)
    Integer findParentIdByOrderId(@Param("orderId") String orderId);

    @Select("select order_id from mallbuilder_product_order where parent_id =#{parentId} group by order_id ")
    @ResultMap("BaseResultMap")
    List<MallbuilderProductOrder> findByParentId(Integer parentId);

}